package com.example.keli.ui.my.adapter;

import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.DataUtil;
import com.example.keli.base.utils.DensityUtil;
import com.example.keli.base.utils.GlideUtil;
import com.example.keli.base.utils.LogUtils;
import com.example.keli.base.utils.ScreenUtil;
import com.example.keli.base.utils.ToastUtil;
import com.example.keli.ui.my.model.LoveSendBean;
import com.example.keli.ui.userinfo.UserInfoDialog;

import java.util.List;

/**
 * description:
 * author: Allen
 * date: 2019/3/19 11:51
 */
public class LoveSendAdapter extends BaseQuickAdapter<LoveSendBean.UserInfoBean, BaseViewHolder> {

    int width = 173 * 2;
    int height = 220 * 2;

    public LoveSendAdapter(List<LoveSendBean.UserInfoBean> mData, Context context) {
        super(R.layout.item_info_common, mData);
        width = (ScreenUtil.getScreenWidth(context) - DensityUtil.dip2px(context, 30)) / 2;
        height = width * 220 / 173;
    }

    @Override
    protected void convert(BaseViewHolder helper, final LoveSendBean.UserInfoBean mListBean) {
        helper.setText(R.id.tv_name, mListBean.getNickname());
        helper.setVisible(R.id.tv_subtitle, true);
        helper.setVisible(R.id.tv_right_title, true);
        int lastDays = DataUtil.getLastDay(mListBean.getGet_wechat_day(), mListBean.getGet_wechat_time());
        if (lastDays > 0){
            //剩余lastDays天
            helper.setText(R.id.tv_subtitle, String.format("微信号: %s", mListBean.getWechat()));
            helper.setText(R.id.tv_right_title, "剩余"+mListBean.getGet_wechat_day()+"天");
            helper.setVisible(R.id.tv_copy, true);
            TextView copy = helper.getView(R.id.tv_copy);
            copy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ClipboardManager cmb = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                    cmb.setText(mListBean.getWechat());
                    ToastUtil.show("复制到剪切板成功");
                }
            });
        }else {
            //已失效
            helper.setText(R.id.tv_subtitle, String.format("微信号: %s", "已失效"));
            helper.setText(R.id.tv_right_title, "已失效");
        }
        helper.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD),R.id.tv_name, R.id.tv_right_title);
        helper.setVisible(R.id.tv_right_subtitle, true);
        helper.setText(R.id.tv_right_subtitle, String.format("备注码:  %s", mListBean.getLove_code()));
        ImageView cover = helper.getView(R.id.iv_avatar);
        GlideUtil.display(cover.getContext(), cover, mListBean.getAvatar());
        cover.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new UserInfoDialog(mContext, mListBean.getBy_uid()).show();
            }
        });
    }

}
